package com.chzc.fm.duotin.widget;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.bean.channel.AnchorSpecial;
import com.chzc.fm.duotin.ui.channel.HostStationActivity;
import com.chzc.fm.duotin.utils.ImageUtil;
import com.chzc.fm.duotin.utils.LogUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by Administrator on 2016/6/24.
 */
public class AnchorItem extends LinearLayout {

    private ImageView ivImag;

    private TextView tvtitle;

    public AnchorItem(Context context, AnchorSpecial special) {
        super(context);
        initViews(context);

        setItems(special);
    }

    public AnchorItem(Context context, AttributeSet attrs) {

        super(context, attrs);

        initViews(context);
    }

    public void initViews(Context context)
    {
        inflate(context,R.layout.anchor_item,this);

        ivImag = (ImageView) findViewById(R.id.anchor_item_iv);
        tvtitle = (TextView) findViewById(R.id.anchor_item_tv);
    }

    /**
     * 设置显示的内容
     * @param special
     */
    public void setItems(final AnchorSpecial special)
    {

        LogUtil.w("(special.getImage_url() = " + special.getImage_url());

        tvtitle.setText(special.getTitle());

        ImageLoader.getInstance().displayImage(special.getImage_url(),ivImag, ImageUtil.getDefaultOptions());

        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if( special.getSub_title() !=null && !special.getSub_title().isEmpty())
                {
                    Intent intent = new Intent(getContext(), HostStationActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("special",special);
                    intent.putExtras(bundle);
                    getContext().startActivity(intent);
                }
            }
        });
    }

}
